package mqpaydemo.paydemo.pay.portal.controller;


import mqpaydemo.paydemo.pay.api.UserService;
import mqpaydemo.paydemo.pay.orm.entity.User;
import mqpaydemo.paydemo.pay.request.UserRequest;
import mqpaydemo.paydemo.pay.response.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ljs
 * @since 2021-09-10
 */
@Controller
@RequestMapping("/pay/user")
public class UserController {
    @Resource
    UserService userService;
    @RequestMapping("/tologin")
    public String tologin(){
        return  "login";
    }

    @PostMapping("/login")
     public String login(UserRequest userRequest, HttpServletRequest request){
        Result<User> result=     userService.login(userRequest);
        User user=result.getData();
        if(user!=null){
        HttpSession session= request.getSession();
            session.setAttribute("user",user);
            return  "toPay";
        }else {
            return  "login";
        }

    }

}
